local blaze = require "blaze"
local game = require "club.threecard.sudoku"

local M = game.ui.element()

function M:ctor(on)
    self.res = "club.threecard.sudoku/ui/common.b:toggle"
    self.on = on
end

local function update(self)
    self.animator:SetBool("Checked", self.on)
end

function M:on_injected(bind)
    if self.on == nil then
        self.on = self.toggle.isOn
    end
    self.animator.keepAnimatorControllerStateOnDisable = true
    bind("toggle.value", self.toggle, self.on_toggle)
    bind("gameobject.enable", self.gameobject, self.on_enable)
    update(self)
end

function M:on_enable()
    update(self)
end

function M:on_toggle(on)
    self.on = on
    update(self)
    if self.on_value_changed then
        self.on_value_changed()
    end
end

function M:set_state(on)
    self.on = on
    update(self)
end

return M